<?php

namespace Common\Model;

/**
 * UserLoginModel.class实例模型
 *
 * @author songanwei
 * @date 2016-1-5
 */
class UserLoginModel extends BaseModel {

    protected $trueTableName = 'bk_user_login';


    /**
     * 获取信息
     * @modify AmosZhong 2016-05-20 创建
     * @param  mixin   $userId        用户id(s)
     * @return array              信息数组
     */
    public function getInfo($userId) {
        $option = array();

        if (is_array($userId)) {
            $userId = implode(',', $userId);
        }
        if (strpos($userId, ',') !== false) {
            $option['id'] = array('in', $userId);
            $data = $this->where($option)->select();
        } else {
            $option['id'] = $userId;
            $data = $this->where($option)->find();
        }

        return empty($data) ? array() : $data;
    }

    /**
     * 获取信息
     * @modify AmosZhong 2016-05-20 创建
     * @param  mixin   $userId        用户id(s)
     * @return array              信息数组
     */
    public function getInfoByUserIds($userId) {
        $option = array();

        if (is_array($userId)) {
            $userId = implode(',', $userId);
        }
        if (strpos($userId, ',') !== false) {
            $option['id'] = array('in', $userId);
        } else {
            $option['id'] = $userId;
        }

        $data = $this->where($option)->select();

        return empty($data) ? array() : $data;
    }


    /**
     * 手机号返回用户数据
     * @modify songanwei 2016-01-05
     * @param string $mobile 手机号
     * @return type
     */
    public function getInfoByMobile($mobile, $areaCode = '86') {
        $where = array(
            'isdelete' => NOT_DELETE,
            'mobile' => $mobile,
            'areacode' => $areaCode
        );
        return $this->where($where)->find();
    }

    /**
     * 添加用户数据
     * @modify songanwei 2016-01-11
     * @param string $mobile  用户手机号
     * @param string $password 密码
     * @param string $headUrl 头像路径
     * @return type
     */
    public function addInfo($mobile, $password, $headUrl = '', $areaCode = '86') {
        $options = array(
            'mobile' => $mobile,
            'password' => $password,
            'headurl' => $headUrl
        );
        $options['areacode'] = $areaCode;

        return $this->add($options);
    }

}
